package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.dao.impl.UserDaoImpl;
import com.qf.pojo.TbUser;
import com.qf.service.UserService;
import com.qf.utils.EmailUtils;

import java.util.concurrent.CompletableFuture;

/*
 *@Description:
 *@author:刘哥
 *@Date:16:44 2022/8/13
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();

    @Override
    public boolean checkUserName(String username) {
        TbUser user=userDao.selectByName(username);
        if (user != null) {
            return true;
        }
        return false;
    }

    @Override
    public TbUser selectByUser(String username) {
        return userDao.selectByName(username);
    }

    @Override
    public void add(TbUser user) {
        userDao.insertUser(user);
//        创建一个型的线程，出错不影响主线程
        CompletableFuture.runAsync(()->{
            EmailUtils.sendEmail(user);
        });

    }

    @Override
    public void activa(String emali, String code) {
        int result=userDao.updateFlag(emali,code);
    }

    @Override
    public void upDateLoginTime(Long id) {
        userDao.upDateLoginTime(id);
    }


}
